<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@include file="../commons/commons.jsp"%>
<!DOCTYPE html>

<head>
    <meta charset="utf-8" />
    <title>Data Tables</title>
</head>
<body>
<div class="page-body">
    <div class="row">
        <div class="col-xs-12 col-md-12">
            <div class="widget">
                <div class="widget-header ">
                    <span class="widget-caption">
        				新增服务内容
                    </span>
                </div>
                <div class="widget-body">
                    <form id="saveOrUpdate" class="form-horizontal form-bordered" role="form" enctype="multipart/form-data" method="post" action="${ ctx}/service/save.do">
                    	<div class="form-group">
	                        <label for="inputEmail3" class="col-sm-2 control-label no-padding-right">图标</label>
	                        <div class="col-sm-10">
	                        	<input id="labelfile" type="file" name="labelfile" required="required" class="file nannyuser" data-show-upload="false"/>
	                        </div>
                        </div>
                        <div class="form-group">
	                        <label for="inputEmail3" class="col-sm-2 control-label no-padding-right">服务名称</label>
	                        <div class="col-sm-10">
	                        	<input type="text" class="form-control" id="serviceName" name="serviceName" 
	                        				placeholder="请输入服务名称" data-bv-notempty="true" data-bv-notempty-message="服务名称不能为空" />
	                        </div>
                       	</div>
                       	 <div class="form-group">
	                        <label for="inputEmail3" class="col-sm-2 control-label no-padding-right">文字描述</label>
	                        <div class="col-sm-10">
	                        	<input type="text" class="form-control" id="serviceDescribe" name="serviceDescribe" 
	                        				placeholder="请输入文字描述" data-bv-notempty="true" data-bv-notempty-message="文字描述不能为空" />
	                        </div>
                       	</div>
                       	 <div class="form-group">
	                        <label for="inputEmail3" class="col-sm-2 control-label no-padding-right">平均薪水</label>
	                        <div class="col-sm-10">
	                        	<input type="text" class="form-control" id="avgSalary" name="avgSalary" 
	                        				placeholder="请输入平均薪水" data-bv-notempty="true" data-bv-notempty-message="平均薪水不能为空" />
	                        </div>
                       	</div>
                       	<div class="form-group">
	                        	<label for="inputEmail3" class="col-sm-2 control-label no-padding-right">基本计费单位</label>
	                        	<div class="col-sm-3">
	                        		<select id="unit" name="unit" class="form-control" required="required">
      									<option value="月">月</option>
      									<option value="小时">小时</option>
      								</select>
	                        	</div>
                       		</div>
                       	<div class="form-group">
	                        <label for="inputEmail3" class="col-sm-2 control-label no-padding-right">优惠套餐一(预约3个月优惠)</label>
	                        <div class="col-sm-10">
	                        	<input type="text" class="form-control" id="discount1" name="discount1" 
	                        				placeholder="请输入优惠套餐一" data-bv-notempty="true" data-bv-notempty-message="优惠套餐一不能为空" />
	                        </div>
                       	</div>
                       	<div class="form-group">
	                        <label for="inputEmail3" class="col-sm-2 control-label no-padding-right">优惠套餐二(预约半年优惠)</label>
	                        <div class="col-sm-10">
	                        	<input type="text" class="form-control" id="discount2" name="discount2" 
	                        				placeholder="请输入优惠套餐二" data-bv-notempty="true" data-bv-notempty-message="优惠套餐二不能为空" />
	                        </div>
                       	</div>
                       	<div class="form-group">
	                        <label for="inputEmail3" class="col-sm-2 control-label no-padding-right">优惠套餐三(预约一年优惠)</label>
	                        <div class="col-sm-10">
	                        	<input type="text" class="form-control" id="discount3" name="discount3" 
	                        				placeholder="请输入优惠套餐三" data-bv-notempty="true" data-bv-notempty-message="优惠套餐三不能为空" />
	                        </div>
                       	</div>
                        <div class="form-group">
                            <div class="col-sm-offset-2 col-sm-10">
                                <a class="btn btn-palegreen" href="javascript:save()">提交</a>
                                <a class="btn btn-palegreen" href="${ctx}/service/list.do">返回</a>
                            </div>
                     	</div>
                 	</form>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script>
	$(document).ready(function () {
	    $('#picUpload').bootstrapValidator();
	});
	var pattern = /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/;
	var save =function(){
		
		if(!$.trim($('#labelfile').val())){
			warningAlert("请上传图片");
			return;
		}
		if(!$.trim($('#serviceDescribe').val())){
			warningAlert("文字描述不能为空");
			return;
		}
		if(!$.trim($('#serviceName').val())){
			warningAlert("服务名称不能为空");
			return;
		}
		if(!$.trim($('#avgSalary').val())){
			warningAlert("平均薪水不能为空");
			return;
		}
		if(!pattern.test($('#avgSalary').val())){
			warningAlert("平均薪水请输入数字");
			return;
		}
		if(!$.trim($('#discount1').val())){
			warningAlert("优惠套餐一不能为空");
			return;
		}
		if(!pattern.test($('#discount1').val())){
			warningAlert("优惠套餐一请输入数字");
			return;
		}
		if(!$.trim($('#discount2').val())){
			warningAlert("优惠套餐二不能为空");
			return;
		}
		if(!pattern.test($('#discount2').val())){
			warningAlert("优惠套餐二请输入数字");
			return;
		}
		if(!$.trim($('#discount3').val())){
			warningAlert("优惠套餐三不能为空");
			return;
		}
		if(!pattern.test($('#discount3').val())){
			warningAlert("优惠套餐三请输入数字");
			return;
		}
		
		
		$(".page-body").block({
                message: "<img src='${ctx}/img/loading.gif' style='width:25px;height:25px'></img><h4>处理中,请稍后...</h4>",
            });
		$("#saveOrUpdate").ajaxSubmit(function(result) {
			  if(result.status == 1){
			  	 infoAlert("添加成功");
				 window.location.href = "${ctx}/service/list.do";
			  }else{
				  warningAlert(result.message[0].msg);
				  $(".page-body").unblock();
			  }
		});
	}

</script>
</html>
